<template>
  <div class="hotworks">
    <div class="hot-conent">
      <div class="item" v-for="(item, index) of hotsong" :key="item.id">
        <span>{{ index + 1 }}</span>
        <div class="music">
          <a href="##" @click="handleClick(item.id)">{{ item.name }}</a>
          <div class="box">
            <a href="##"
              ><span
                class="iconfont icon-jiahao"
                @click="handlePaly(item)"
              ></span
            ></a>
            <a href="##">
              <span
                class="iconfont icon-xiai"
                @click="handleCollect(item)"
              ></span>
            </a>
          </div>
        </div>
        <div class="timer">{{ item.dt | handleTime }}</div>
        <div class="album">{{ item.al.name | handleString }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hotsong: [],
    };
  },
  mounted() {
    // console.log(this.$route.query);
    var { id } = this.$route.query;
    this.$http.get(`/artists?id=${id}`).then((res) => {
      this.hotsong = res.data.hotSongs;
    });
  },
  methods: {
    handleClick(val) {
      this.$router.push(`/play?id=${val}`);
    },
    handlePaly(val) {
      console.log(val);
      this.$https.post("/playmusic", { val }).then((res) => {
        if (res.data.code == 400) {
          this.$message({
            showClose: true,
            message: "已经添加，请不要重复添加",
          });
        }
        this.$bus.$emit("shuaxin");
      });
    },
    handleCollect(val) {
      console.log(val);
      this.$https.post("/musiccollect", { val }).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style scoped>
.hot-conent {
  background-color: #f1f1f1;
  padding: 20px 0;
  border-radius: 20px;
  margin-top: 20px;
}
.item {
  font-size: 14px;
  padding: 0px 20px;
  line-height: 40px;
  display: flex;
}
.item span {
  width: 120px;
}
.music {
  display: flex;
  justify-content: space-between;
  width: 300px;
}
.music a:hover {
  color: #abc4ff;
}
.timer {
  color: #c9c9c9;
  width: 120px;
}
.album {
  width: 160px;
}
.item:nth-child(2n) {
  background-color: #f7f7f7;
}
.box {
  width: 70px;
  display: none;
}
.item:hover .box {
  display: block;
}
.box span {
  margin-left: 10px;
}
.box .icon-xiai:hover {
  color: red;
}
.box .icon-jiahao {
  color: #abc4ff;
}
</style>